<script setup lang="ts">
import { stringify } from "querystring";
import { ref, reactive } from "vue";
import { Ref } from "vue";
import { MoreFilled } from "@element-plus/icons-vue";

// 跳转
const router = useRouter();

// 传值
const props = defineProps({
  accordionList: {
    type: Array<any>,
    required: true,
  },
  // 手风琴标题
  title: {
    type: String,
  },
});

const active: Ref<number> = ref(0);
const activeChange = (index: number) => {
  // index 当前选择的第几个
  if (active.value === index) {
    console.log("可以跳转", props.accordionList[index]);
    return;
  }
  active.value = index;
};

// setInterval(() => {
//   if (active.value >= props.modelValue.length - 1) {
//     active.value = 0;
//     return;
//   }
//   active.value++;
// }, 1000);
</script>

<template>
  <el-skeleton animated :loading="accordionList.length <= 0">
    <template #template>
      <el-skeleton-item variant="caption" style="height: 30px" />
      <el-skeleton-item variant="caption" style="height: 200px" />
    </template>

    <template #default>
      <div class="accordion" v-if="accordionList.length > 0">
        <h3>{{ title }}</h3>
        <h6>
          {{ accordionList[active].name }}
          <span>更多 ></span>
        </h6>

        <div class="warp">
          <el-image
            v-for="(item, key) in accordionList"
            :key="key"
            lazy
            :title="item.name"
            :src="item.picUrl"
            fit="cover"
            loading="lazy"
            @click="activeChange(key)"
            :class="active == key ? 'card-hover card' : 'card'"
          >
            <template #error>
              <el-image src="../assets/vue.svg" fit="cover"></el-image>
            </template>
          </el-image>
        </div>
      </div>
    </template>
  </el-skeleton>
</template>

<style scoped lang="scss">
.accordion {
  margin-top: 20px;

  h3,
  h6 {
    margin-bottom: 5px;
  }
  h3 {
    float: left;
  }
  h6 {
    float: right;
    span {
      margin-left: 10px;
    }
    span:hover {
      color: var(--el-color-primary);
      cursor: pointer;
    }
  }
}

.warp {
  display: flex;
  flex-flow: row nowrap;
  justify-content: center;
  align-items: center;
  margin: 0 auto;
  width: 100%;
  -moz-user-select: none;
  -o-user-select: none;
  -khtml-user-select: none;
  -webkit-user-select: none;
  -ms-user-select: none;
  user-select: none;
}
.warp .card {
  background-position: center;
  background-size: auto;
  background-repeat: no-repeat;
  border-radius: 20px;
  color: var(--el-color-white);
  flex: 0.5;
  cursor: pointer;
  height: 200px;
  margin: 5px;
  position: relative;
  opacity: 0.7;
  transition: flex 0.7s cubic-bezier(0.05, 0.6, 0.4, 0.9);
}
.warp .card:hover {
  background-size: auto 100% cover;
  object-fit: cover;
  opacity: 1 !important;
  transition: all 0.7s cubic-bezier(0.05, 0.6, 0.4, 0.9);
}
.card-hover {
  flex: 1.5 !important;
  background-size: auto 100% cover;
  object-fit: cover;
  opacity: 1 !important;
  // filter: drop-shadow(0 0 0.7em #8f4b2eaa);
  transition: all 0.7s cubic-bezier(0.05, 0.6, 0.4, 0.9);
}

@media (max-width: 500px) {
  .warp {
    width: 100%;
  }

  .card:nth-last-of-type(-n + 2) {
    display: none;
  }
}
</style>
